package com.myapp.ruyixing.http;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import com.myapp.ruyixing.model.ReviewList;

public class ReviewListParser extends RYJSONParser {
	@Override
	public Object parse(JSONObject jsonObject) {
		ReviewList reviewList = new ReviewList();

		ListModelParser.parseListModel(reviewList, jsonObject);
		JSONObject data = jsonObject.optJSONObject("data");
		JSONArray array = data.optJSONArray("items");
		reviewList.items = new ArrayList<ReviewList.Review>();
		for (int i = 0; array != null && i < array.length(); i++) {
			JSONObject object = array.optJSONObject(i);
			if (object != null) {
				ReviewList.Review review = new ReviewList.Review();
				review.content = object.optString("content", "content");
				review.datetime = object.optString("datetime", "datetime");
				review.id = object.optString("id", "");
				review.title = object.optString("title", "title");
				review.fuwu = object.optString("fuwu", "0");
				review.weisheng = object.optString("weisheng", "0");
				review.pingjia = object.optString("pingjia", "0");
				review.username = object.optString("username", "username");
				reviewList.items.add(review);
			}
		}

		return reviewList;

	}
}
